<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://unpkg.com/vue"></script>
    <script>
        window.onload=function(){
            var app4 = new Vue({
                el: '#app-4',
                methods: {
                    addpeople: function () {
                        this.message = this.todos.push({ name: this.user,age:this.age ,time:new Date()})
                    },
                    removeAll:function(){
                    this.todos=[]
                    },
                    removeThis:function(ind){
                        this.todos.splice(ind,1)
                    }
                },
                data: {
                    user:'',
                    age:'',
                    todos: [
                        { xuhao: '',name:'wff',age:'12',time:new Date(),option:'' },
                        { xuhao:'',name:'xdd',age:'22',time:new Date(),option:''},
                    ]
                },
                    filters:{
                        hhmmss:function(val){
                        return(val.getHours()+":"+val.getMinutes()+":"+val.getSeconds())
                    },
                        capitalize: function (value) {
                            if (!value) return ''
                            value = value.toString()
                            return value.charAt(0).toUpperCase() + value.slice(1)
                        }
                }
            })
        }
    </script>
</head>
<body>
<div id="app-4">
    <button v-on:click="addpeople">添加</button>
    <button v-on:click="removeAll">删除所有</button>
    <input v-model="user">
    <input v-model="age">
    <table border="1">
        <tr>
            <td>序号</td>
            <td>名字</td>
            <td>年龄</td>
            <td>时间</td>
            <td>操作</td>
        </tr>
        <tr v-for="(todo,index) in todos">
            <td >{{index+1}}</td>
            <td>{{todo.name| capitalize}}</td>
            <td>{{todo.age}}</td>
            <td>{{todo.time|hhmmss}}</td>
            <td><button v-on:click="removeThis(index)">删除本行</button></td>
        </tr>
    </table>
</div>
</body>
</html>